package com.acme.domain.account;

import com.acme.exceptions.NoEnoughFundsException;

public class SavingAccount extends AbstractAccount {

    private static final long serialVersionUID = -6930996674834661789L;

    public SavingAccount(final int id, final double amount) {
	super(id, amount);
    }

    @Override
    public void deposit(final double amount) throws IllegalArgumentException {
	if (amount < 0) {
	    throw new IllegalArgumentException("Amount can not be negative");
	}
	balance += amount;
    }

    @Override
    public AccountType getAccountType() {
	return AccountType.SAVING;
    }

    @Override
    public String toString() {
	return "Saving account with amount: " + getBalance() + "$";
    }

    @Override
    public void withdraw(final double amount) throws NoEnoughFundsException {
	if (amount < 0) {
	    throw new IllegalArgumentException("Amount can not be negative");
	}
	if (balance - amount >= 0) {
	    balance -= amount;
	} else {
	    throw new NoEnoughFundsException(amount);
	}

    }
}
